package duyd.transaction.training.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

@Entity
@Table(name = "CONTACT")
@NamedQueries({ 
    @NamedQuery(name = "contact.findByBirthDate", query = "select c from Contact c where c.birthDate = :birthDate"),
    @NamedQuery(name = "contact.findAll", query = "select c from Contact c"),
    @NamedQuery(name = "contact.countAll", query = "select count(c) from Contact c"),
    @NamedQuery(name = "contact.findByName", query = "select c from Contact c where c.firstName = :firstName and c.lastName = :lastName") })
public class Contact implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -1993547476357963894L;

    private Long id;

    private int version;

    private String firstName;

    private String lastName;

    private Date birthDate;

    public Contact() {

    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CONTACT_ID")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Version
    @Column(name = "CONTACT_VERSION")
    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    @Column(name="FIRST_NAME")
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name="LAST_NAME")
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "BIRTH_DATE")
    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public String toString() {
        return "Contact[id: " + id + 
                "; first name: " + firstName + 
                "; last name: " + lastName + 
                "; birthdate: " + birthDate + "]";
    }

}
